#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

#include   <windows.h>

#define high 20

#define width 25

int cells[high][width];

int i, j;

int cellsnumber;

int tempcells[high][width];

void gotoxy(int a, int b)

{

HANDLE hout;

COORD coord;





coord.X = a;

coord.Y = b;





hout = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleCursorPosition(hout, coord);

}

void clrscr()

{

system("cls");

}

void startup()

{

for(i=0;i<high;i++)

for (j = 0; j < width; j++)

{

cells[i][j] = rand()%2;

}

for (i = 0; i < high; i++)

for (j = 0; j < width; j++)

{

tempcells[i][j] = cells[i][j];

}

}

void show()

{

int i, j;

gotoxy(0, 0);

for (i = 0; i <high; i++)

{

for (j = 0; j < width; j++)

{

if (cells[i][j]==1)

printf("*");

else

printf(" ");

}

printf("\n");

}

}



void updateWithoutInput()

{

for(i=1;i<high-1;i++)

for (j = 1; j < width - 1; j++)

{

cellsnumber = cells[i - 1][j - 1] + cells[i - 1][j] + cells[i - 1][j +1] +

cells[i ][j - 1] + cells[i][j ] + cells[i ][j + 1] +

cells[i + 1][j - 1] + cells[i + 1][j ] + cells[i + 1][j + 1];

if (cellsnumber == 3)

{

tempcells[i][j] = 1;

}

else if (cellsnumber == 2)

{

tempcells[i][j] = cells[i][j];

}

else

tempcells[i][j] = 0;

}

for (i = 1; i < high - 1; i++)

for (j = 1; j < width - 1; j++)

{

cells[i][j] = tempcells[i][j];

}



Sleep(150);



}

int main()

{

startup();

while (1)

{

show();

updateWithoutInput();

}

}
